package handler

import (
	"boos-recruit/cache"
	"boos-recruit/moderl"
	"encoding/json"
	"github.com/gin-gonic/gin"
	"strconv"
	"time"
)

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
	size, _ := strconv.Atoi(c.DefaultQuery("size", "2"))

	offset := (page - 1) * size

	var count int64
	moderl.DB.Model(moderl.Boss{}).Count(&count)

	var xq []moderl.Boss
	err := moderl.DB.Order("desc").Offset(offset).Limit(size).Find(&xq).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "查询失败",
		})
		return
	}

}
func Xq(c *gin.Context) {
	id := c.Query("id")
	var qq moderl.Boss

	redis_key := "qq_id" + id
	moderl.DB.Where("id = ?", id).Find(&qq)
	jsonData, _ := json.Marshal(&qq)
	cache.Rdb.Set(cache.Ctx, redis_key, jsonData, time.Hour*2)
	c.JSON(200, gin.H{
		"code": 500,
		"msg":  "查询失败",
		"data": qq,
	})
	return
}
